// 自定义指令
import Vue from 'vue'
import store from '@/store'

// 处理图片失效的自定义指令
Vue.directive('imagerror', {
  inserted(el, { value }) {
    if (!el.src) {
      el.src = value
    }
    el.onerror = function() {
      el.src = value
    }
  },
  update(el, { value }) {
    if (!el.src) {
      el.src = value
    }
    el.onerror = function() {
      el.src = value
    }
  }
})

// 处理按钮级别的显示和隐藏
Vue.directive('showbutton', {
  inserted(el, { value }) {
    const roles = store.state.user.userInfo.roles
    const has = roles?.points.some(item => item === value)
    if (!has) {
      el.remove()
    }
  }
})
